<!DOCTYPE html><html lang="[&quot;zh-Hans&quot;,&quot;zh-CN&quot;,&quot;default&quot;]"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"><meta name="description" content="npm install各种方式的介绍"><meta name="keywords" content="npm,install"><meta name="author" content="wenmu"><meta name="copyright" content="wenmu"><title>npm install各种方式的介绍 | 温木的博客</title><link rel="shortcut icon" href="/melody-favicon.ico"><link rel="stylesheet" href="/css/index.css?version=1.6.1"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@latest/css/font-awesome.min.css?version=1.6.1"><link rel="dns-prefetch" href="https://cdn.staticfile.org"><link rel="dns-prefetch" href="https://cdn.bootcss.com"><link rel="dns-prefetch" href="https://creativecommons.org"><link rel="dns-prefetch" href="http://ta.qq.com"><script>(function() {
   var hm = document.createElement("script");
   hm.src = "https://tajs.qq.com/stats?sId=&lt;script type=&quot;text/javascript&quot; src=&quot;http://tajs.qq.com/stats?sId=66523541&quot; charset=&quot;UTF-8&quot;&gt;&lt;/script&gt;";
   var s = document.getElementsByTagName("script")[0];
   s.parentNode.insertBefore(hm, s);
 })();</script><script>var GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  }
} </script><meta name="generator" content="Hexo 4.2.0"></head><body><i class="fa fa-arrow-right" id="toggle-sidebar" aria-hidden="true"></i><div id="sidebar"><div class="toggle-sidebar-info text-center"><span data-toggle="切换文章详情">切换站点概览</span><hr></div><div class="sidebar-toc"><div class="sidebar-toc__title">目录</div><div class="sidebar-toc__progress"><span class="progress-notice">你已经读了</span><span class="progress-num">0</span><span class="progress-percentage">%</span><div class="sidebar-toc__progress-bar"></div></div><div class="sidebar-toc__content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-npm-install"><span class="toc-number">1.</span> <span class="toc-text">1. npm install</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-npm-install-folder"><span class="toc-number">2.</span> <span class="toc-text">2. npm install folder</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-npm-install"><span class="toc-number">3.</span> <span class="toc-text">3. npm install </span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-npm-install"><span class="toc-number">4.</span> <span class="toc-text">4.npm install </span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-npm-install-lt-scope-gt"><span class="toc-number">5.</span> <span class="toc-text">5. npm install [&lt;@scope&gt;&#x2F;]</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-npm-install-lt-scope-gt"><span class="toc-number">6.</span> <span class="toc-text">6. npm install [&lt;@scope&gt;&#x2F;]@</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#7-npm-install-lt-scope-gt"><span class="toc-number">7.</span> <span class="toc-text">7. npm install [&lt;@scope&gt;&#x2F;]@</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#8-npm-install"><span class="toc-number">8.</span> <span class="toc-text">8. npm install </span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#9-npm-install"><span class="toc-number">9.</span> <span class="toc-text">9. npm install &#x2F;[#]</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#10-npm-install-gitlab"><span class="toc-number">10.</span> <span class="toc-text">10. npm install gitlab:&#x2F;[#]</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#总结"><span class="toc-number">11.</span> <span class="toc-text">总结</span></a></li></ol></div></div><div class="author-info hide"><div class="author-info__avatar text-center"><img src="https://i.loli.net/2020/02/27/xwaBoOj158MfNyq.jpg"></div><div class="author-info__name text-center">wenmu</div><div class="author-info__description text-center">记录一些在工作中或学习新知识时学到的一些知识点；正所谓好记性不如一个烂笔头，温故而知新！</div><hr><div class="author-info-articles"><a class="author-info-articles__archives article-meta" href="/archives"><span class="pull-left">文章</span><span class="pull-right">115</span></a><a class="author-info-articles__tags article-meta" href="/tags"><span class="pull-left">标签</span><span class="pull-right">52</span></a><a class="author-info-articles__categories article-meta" href="/categories"><span class="pull-left">分类</span><span class="pull-right">30</span></a></div></div></div><div id="content-outer"><div class="no-bg" id="top-container"><div id="page-header"><span class="pull-left"> <a id="site-name" href="/">温木的博客</a></span><i class="fa fa-bars toggle-menu pull-right" aria-hidden="true"></i><span class="pull-right menus"><a class="site-page" href="/">首页</a><a class="site-page" href="/archives">文章</a><a class="site-page" href="/tags">标签</a><a class="site-page" href="/categories">分类</a></span></div><div id="post-info"><div id="post-title">npm install各种方式的介绍</div><div id="post-meta"><time class="post-meta__date"><i class="fa fa-calendar" aria-hidden="true"></i> 2020-01-09</time><span class="post-meta__separator">|</span><i class="fa fa-inbox post-meta__icon" aria-hidden="true"></i><a class="post-meta__categories" href="/categories/npm/">npm</a></div></div></div><div class="layout" id="content-inner"><article id="post"><div class="article-container" id="post-content"><h3 id="1-npm-install"><a href="#1-npm-install" class="headerlink" title="1. npm install"></a>1. npm install</h3><p>安装<code>package.json</code>中依赖的所有包。</p>
<h3 id="2-npm-install-folder"><a href="#2-npm-install-folder" class="headerlink" title="2. npm install folder"></a>2. npm install folder</h3><p>folder 其实就是包名，从 npm 源上安装指定的包。</p>
<h3 id="3-npm-install"><a href="#3-npm-install" class="headerlink" title="3. npm install "></a>3. npm install <tarball file></h3><p>安装本地的压缩包文件。如果要安装开发中的目录，则可以使用<code>npm link</code></p>
<h3 id="4-npm-install"><a href="#4-npm-install" class="headerlink" title="4.npm install "></a>4.npm install <tarball url></h3><p>根据压缩文件的<code>url</code>来安装，但是<code>url</code>必须是以<code>http://</code>或<code>https://</code>开头。</p>
<h3 id="5-npm-install-lt-scope-gt"><a href="#5-npm-install-lt-scope-gt" class="headerlink" title="5. npm install [&lt;@scope&gt;/]"></a>5. npm install [&lt;@scope&gt;/]<name></h3><p>安装指定范围下面的某个包。<br>如果范围前面没加@符号，则会被认为是 github 的仓库名。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">npm install githubname/reponame</span><br><span class="line">npm install @myorg/privatepackage</span><br></pre></td></tr></table></figure>

<h3 id="6-npm-install-lt-scope-gt"><a href="#6-npm-install-lt-scope-gt" class="headerlink" title="6. npm install [&lt;@scope&gt;/]@"></a>6. npm install [&lt;@scope&gt;/]<name>@<tag></h3><p>加 tag</p>
<h3 id="7-npm-install-lt-scope-gt"><a href="#7-npm-install-lt-scope-gt" class="headerlink" title="7. npm install [&lt;@scope&gt;/]@"></a>7. npm install [&lt;@scope&gt;/]<name>@<version></h3><p>加版本</p>
<h3 id="8-npm-install"><a href="#8-npm-install" class="headerlink" title="8. npm install "></a>8. npm install <git remote url></h3><p>安装 git 链接的包。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;protocol&gt;://[&lt;user&gt;[:&lt;password&gt;]@]&lt;hostname&gt;[:&lt;port&gt;][:][/]&lt;path&gt;[<span class="comment">#&lt;commit-ish&gt; | #semver:&lt;semver&gt;]</span></span><br></pre></td></tr></table></figure>

<p><code>protocol</code>(协议)是以下<code>git, git+ssh, git+http, git+https, or git+file</code>其中之一。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">npm install git+ssh://git@github.com:npm/cli.git<span class="comment">#v1.0.27</span></span><br><span class="line">npm install git+ssh://git@github.com:npm/cli<span class="comment">#semver:^5.0</span></span><br><span class="line">npm install git+https://isaacs@github.com/npm/cli.git</span><br><span class="line">npm install git://github.com/npm/cli.git<span class="comment">#v1.0.27</span></span><br><span class="line">GIT_SSH_COMMAND=<span class="string">'ssh -i ~/.ssh/custom_ident'</span> npm install git+ssh://git@github.com:npm/cli.git</span><br></pre></td></tr></table></figure>

<h3 id="9-npm-install"><a href="#9-npm-install" class="headerlink" title="9. npm install /[#]"></a>9. npm install <githubname>/<githubrepo>[#<commit-ish>]</h3><p>安装 github 上的包，其实也是通过 8 中 git 获取到，然后安装。</p>
<h3 id="10-npm-install-gitlab"><a href="#10-npm-install-gitlab" class="headerlink" title="10. npm install gitlab:/[#]"></a>10. npm install gitlab:<gitlabname>/<gitlabrepo>[#<commit-ish>]</h3><p>安装 gitlab 官网的包，也是通过 8 中的 git 获取，然后安装。</p>
<h3 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h3><p>其实<code>npm install</code> 可以安装各种源的包，只要设置的方法能获取包的文件即可。</p>
</div></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">wenmu</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://blog.wangpengpeng.site/2020/01/09/npm-install%E5%90%84%E7%A7%8D%E6%96%B9%E5%BC%8F%E7%9A%84%E4%BB%8B%E7%BB%8D/">http://blog.wangpengpeng.site/2020/01/09/npm-install%E5%90%84%E7%A7%8D%E6%96%B9%E5%BC%8F%E7%9A%84%E4%BB%8B%E7%BB%8D/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" rel="noopener">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://blog.wangpengpeng.site">温木的博客</a>！</span></div></div><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/npm/">npm</a><a class="post-meta__tags" href="/tags/install/">install</a></div><div class="post-qr-code"><div class="post-qr-code-item"><img class="post-qr-code__img" src="https://i.loli.net/2020/02/27/hOBzIxFDJMCrmtN.jpg"><div class="post-qr-code__desc">微信打赏</div></div></div><nav id="pagination"><div class="prev-post pull-left"><a href="/2020/01/09/10%E5%A4%A9%E5%BD%BB%E5%BA%95%E6%90%9E%E5%AE%9Awebpack4-0-%E7%AC%94%E8%AE%B0-1/"><i class="fa fa-chevron-left">  </i><span>10天彻底搞定webpack4.0-笔记(1)</span></a></div><div class="next-post pull-right"><a href="/2020/01/09/npm-link/"><span>npm link</span><i class="fa fa-chevron-right"></i></a></div></nav><div id="vcomment"></div><script src="https://cdn1.lncld.net/static/js/3.0.4/av-min.js"></script><script src="https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js"></script><script>var notify = 'false' == true ? true : false;
var verify = 'false' == true ? true : false;
var GUEST_INFO = ['nick','mail','link'];
var guest_info = 'nick,mail,link'.split(',').filter(function(item){
  return GUEST_INFO.indexOf(item) > -1
});
guest_info = guest_info.length == 0 ? GUEST_INFO :guest_info;
window.valine = new Valine({
  el:'#vcomment',
  notify:notify,
  verify:verify,
  appId:'U1QqpeQNuBnRsfygHk1GQ30q-gzGzoHsz',
  appKey:'dunDQzEseDzgsKgw4qLQcog1',
  placeholder:'支持markdown！',
  avatar:'wavatar',
  guest_info:guest_info,
  pageSize:'20',
  lang: 'zh-cn'
})</script></div></div><footer><div class="layout" id="footer"><div class="copyright">&copy;2019 - 2020 By wenmu</div><div class="framework-info"><span>驱动 - </span><a href="http://hexo.io" target="_blank" rel="noopener"><span>Hexo</span></a><span class="footer-separator">|</span><span>主题 - </span><a href="https://github.com/Molunerfinn/hexo-theme-melody" target="_blank" rel="noopener"><span>Melody</span></a></div><div class="busuanzi"><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><span id="busuanzi_container_page_pv">该文访问量<span id="busuanzi_value_page_pv"></span><span></span></span></div></div></footer><i class="fa fa-arrow-up" id="go-up" aria-hidden="true"></i><script src="https://cdn.jsdelivr.net/npm/animejs@latest/anime.min.js"></script><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-animate@latest/velocity.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-ui-pack@latest/velocity.ui.min.js"></script><script src="/js/utils.js?version=1.6.1"></script><script src="/js/fancybox.js?version=1.6.1"></script><script src="/js/sidebar.js?version=1.6.1"></script><script src="/js/copy.js?version=1.6.1"></script><script src="/js/fireworks.js?version=1.6.1"></script><script src="/js/transition.js?version=1.6.1"></script><script src="/js/scroll.js?version=1.6.1"></script><script src="/js/head.js?version=1.6.1"></script><script>if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
  $('#nav').addClass('is-mobile')
  $('footer').addClass('is-mobile')
}</script></body></html>